package com.lfs.admin.controller.dataPackage;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.json.JSONObject;
import com.lfs.admin.model.entity.dataPackage.DataReleaseDetailEntity;
import com.lfs.admin.model.entity.dataPackage.DataReleaseTaskEntity;
import com.lfs.admin.model.entity.dataPackage.DataRepositoryEntity;
import com.lfs.admin.model.vo.DataReleaseDetailVo;
import com.lfs.admin.model.vo.DataReleaseVo;
import com.lfs.admin.model.vo.DataRepositoryVo;
import com.lfs.admin.service.DataReleaseService;
import com.lfs.admin.service.DataRepositoryService;
import com.lfs.base.dto.Result;
import com.lfs.base.dto.ResultObject;
import com.lfs.base.exception.BusinessException;
import com.lfs.common.annotation.Log;
import com.lfs.common.core.controller.BaseController;
import com.lfs.common.enums.BusinessType;
import com.lfs.dao.entity.PageBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javafx.print.Collation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Collection;
import java.util.List;

@RestController
@RequestMapping("/dataRelease")
@Api(value = "数据包发布管理", tags = {"数据包发布管理"})
public class DataReleaseController extends BaseController {

    @Autowired
    private DataReleaseService dataReleaseService;


    @Log(title = "数据包发布列表", businessType = BusinessType.INSERT)
    @ApiOperation(value = "数据包发布列表")
    @PostMapping("/queryReleaseList")
    public Result<?> queryReleaseList(@RequestBody DataReleaseVo dataReleaseVo) {

        if (null == dataReleaseVo) {
            throw new BusinessException("需要数据包发布列表的参数为空!");
        }
        PageBean<DataReleaseTaskEntity> dataReleaseList = dataReleaseService.queryDataReleaseList(dataReleaseVo);
        return ResultObject.successObject(dataReleaseList,"success");
    }

    @Log(title = "数据包发布记录详情", businessType = BusinessType.INSERT)
    @ApiOperation(value = "数据包发布记录详情")
    @PostMapping("/queryReleaseDetail")
    public Result<?> queryReleaseDetail(@RequestBody DataReleaseDetailVo dataReleaseDetailVo) {

        if (null == dataReleaseDetailVo) {
            throw new BusinessException("需要查询的数据包发布记录详情的参数为空!");
        }
        PageBean<DataReleaseDetailEntity> dataReleaseList = dataReleaseService.queryDataReleaseDetailList(dataReleaseDetailVo);
        return ResultObject.successObject(dataReleaseList,"success");
    }

    @ApiOperation(value = "删除数据包发布记录")
    @DeleteMapping("/deleteReleaseTask/{ids}")
    public Result<?> deleteReleaseTask(@PathVariable Integer[] ids) {

        if (null == ids) {
            throw new BusinessException("删除数据包发布记录接口参数不能为空!");
        }
        logger.info("根据批量发布id删除数据包发布记录");
        return ResultObject.successObject(dataReleaseService.deleteDataRelease(ids), "删除数据包发布记录成功");
    }
}
